 var directionsDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;
  var oldDirections = [];
  var currentDirections = null;

  function miFuncion() {

    directionsDisplay = new google.maps.DirectionsRenderer({
        'map': map,
        'preserveViewport': true,
        'draggable': true
    });
    directionsDisplay.setPanel(document.getElementById("directions_panel"));

    google.maps.event.addListener(directionsDisplay, 'directions_changed',
      function() {
        if (currentDirections) {
          oldDirections.push(currentDirections);
          setUndoDisabled(false);
        }
        currentDirections = directionsDisplay.getDirections();
      });

    setUndoDisabled(true);
    
    if($('#origen').length > 0){
		var autocomp = new google.maps.places.Autocomplete(
				$("#origen")[0], {
					componentRestrictions: {country: 'ar'},
					types:new Array('(cities)'),
				});

		google.maps.event.addListener(autocomp,'place_changed',function(e){
			calcRoute(this.getPlace().formatted_address);
		});
	}
    var marker= new google.maps.Marker({
		position: new google.maps.LatLng($('input[name=lat]').val(),$('input[name=lng]').val()),
		map:map,
		title: $('#destino').val(),
	}); 
	var image = new google.maps.MarkerImage(
			'../../images/grn-pushpin.png',
			new google.maps.Size(64, 64),
			new google.maps.Point(0, 0),
			new google.maps.Point(10, 32),
			new google.maps.Size(32, 32));
	/*'../../images/marker_sprite_green.png',
	new google.maps.Size(19, 32),
	new google.maps.Point(0, 1));*/
	marker.setIcon(image);
  }

  function calcRoute(origen) {
    var start = origen;
    var coord_dest = new google.maps.LatLng($('input[name=lat]').val(),$('input[name=lng]').val());
    var end = coord_dest;
    var request = {
        origin:start,
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
  }

  function undo() {
 /*   currentDirections = null;
    directionsDisplay.setDirections(oldDirections.pop());
    if (!oldDirections.length) {
      setUndoDisabled(true);
    }*/
  }

  function setUndoDisabled(value) {
   // document.getElementById("undo").disabled = value;
  }